<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .col {
      color: transparent;
    }
  </style>
</head>

<body>
  <script>
    // while实现1-100相加求和
    var a = 1;
    var sum = 0
    while (a <= 100) {
      sum = sum + a;
      a++;
    }
    document.write("1+2+3+...+100=" + sum);
    document.write('<br>');
    // while do...while验证用户名和密码
     do {
      var username = prompt("请输入用户名：");
      var password = prompt("请输入密码：");
      if (username == "123" && password == "123") {
        alert("登录成功！");
        break;
      } else {
        alert("登录失败！");
      }
    } while (true); 
    // 打印三角形
    for (var i = 1; i <= 5; i++) {
      for (var j = 5; j > i; j--) {
        document.write('<span class="col">*</span>');
      }
      for (var k = 1; k <= 2 * i - 1; k++) {
        document.write('*');
      }
      document.write('<br>');
    }
    // 菱形
    for (var i = 1; i <= 5; i++) {
      for (var j = 5; j > i; j--) {
        document.write('<span class="col">*</span>');
      }
      for (var k = 1; k <= 2 * i - 1; k++) {
        document.write('*');
      }
      document.write('<br>');
    }
    for (var i = 4; i >= 1; i--) {
      for (var j = 5; j > i; j--) {
        document.write('<span class="col">*</span>');
      }
      for (var k = 1; k <= 2 * i - 1; k++) {
        document.write('*');
      }
      document.write('<br>');
    }
    /* 一百个和尚分一百个馒头，大和尚一人分三个，小和尚三人分一个，正好分完。问大、小和尚各几人？ */
    for (var b = 0; b <= 100; b++) {
      for (var c = 0; c <= 100; c++) {
        if (b + c === 100 && (3 * b + 1 / 3 * c) === 100) {
          document.write('大和尚 ' + b + '人' + '小和尚' + c + '人。');
        }
      }
    }
    document.write('<br>');
    /*  公鸡一个五块钱，母鸡一个三块钱，小鸡三个一块钱，现在要用一百块钱买一百只鸡，问公鸡、母鸡、小鸡各多少只？ */
    for (var i = 0; i <= 100; i++) {
      for (var j = 0; j <= 100; j++) {
        for (var k = 0; k <= 100; k++) {
          if (i + j + k === 100 && (5 * i + 3 * j + k / 3) === 100) {
            document.write('公鸡' + i + '只&nbsp;' + '母鸡' + j + '只&nbsp;' + '小鸡' + k + '只');
            document.write('<br>');
          }
        }
      }
    }
    /* 红白球共25个，白黑球共31个，红黑球共28个，求三种球各有多少？求红白黑球的个数 */
    for (var i = 0; i <=28; i++) {
      for (var j = 0; j <=31; j++) {
        for (var k = 0; k <=31; k++) {
          if (i + j === 25 && j + k === 31 && i + k === 28) {
            document.write('红球' + i + '个&nbsp;' + '白球' + j + '个&nbsp;' + '黑球' + k + '个');
          }
        }

      }

    }
  </script>


</body>

</html>